<script setup lang="ts">
import {onUnmounted, ref} from "vue";
import emitter from "@/utils/emitter";

let computer = ref('联想')
let toy = ref('')
emitter.on('send-toy', (value:string) => {
  toy.value = value
})

onUnmounted(() => {
  // 释放内存
  emitter.off('send-toy')
})
</script>

<template>
<h2>子组件2</h2>
  <h3>电脑：{{computer}}</h3>
  <h3 v-show="toy">拿到玩具：{{toy}}</h3>
</template>

<style scoped>

</style>